﻿
--网站项目完结
CREATE PROCEDURE [dbo].[proc_Project_Finish_ByPId]
(
	@ProjectId uniqueidentifier
)
As
Begin
	Declare @Title nvarchar(200),@RevTitle nvarchar(200),@n int
	Declare @DSum int, @DFinishSum int

	--取该项目的任务数
	Select @DSum=Count(0) From Project_Task Where ProjectId=@ProjectId And ProductId In(select id from Product where flag=1)	-- And WebType>0
	If(@DSum=0)
	Begin
		Select -1 As ReturnValue
		Return	--未下发任务
	End

	--取该项目未完成的任务数(含部门和个人)
	Select @DFinishSum=Count(0) From Project_Task Where ProjectId=@ProjectId And IsFinish=0 And ProductId In(select id from Product where flag=1) -- And WebType>0
	If(@DFinishSum>0)
	Begin
		Select 0 As ReturnValue
		Return	--有未完成的任务
	End

	Update Project Set IsFinish=1 Where ProjectId=@ProjectId And ProductId In(select id from Product where flag=1)	--置该网站项目的完成标志
	Update Project Set FinishDate=GetDate() Where ProjectId=@ProjectId And ProductId In(select id from Product where flag=1) And FinishDate Is Null	--分两步置完成标志和完成日期，目的是确保完成日期唯一(完成标志是随任务变化而变化的)
	Select 1 As ReturnValue
	Return
End